package com.huangliusong;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ReadDirectory {
	/**
	 * 获取路径下的所有文件/文件夹
	 * 
	 * @param directoryPath
	 *            需要遍历的文件夹路径
	 * @param isAddDirectory
	 *            是否将子文件夹的路径也添加到list集合中
	 * @return
	 */
	public static List<String> getAllFile(String directoryPath,
			boolean isAddDirectory) {
		List<String> list = new ArrayList<String>();
		File baseFile = new File(directoryPath);
		if (baseFile.isFile() || !baseFile.exists()) {
			return list;
		}
		File[] files = baseFile.listFiles();
		for (File file : files) {
			if (file.isDirectory()) {
				if (isAddDirectory) {
					list.add(file.getAbsolutePath());
				}
				list.addAll(getAllFile(file.getAbsolutePath(), isAddDirectory));
			} else {
				list.add(file.getAbsolutePath());
			}
		}
		return list;
	}

	public static void main(String[] args) {

	}

	public void saoMiaoFile() {
		List<String> list = getAllFile("D:\\hlsXML", true);
		for (int i = 0; i < list.size(); i++) {
			File file = new File(list.get(i));
			long time = file.lastModified();// 返回文件最后修改时间，是以个long型毫秒数
			String ctime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
					.format(new Date(time));
			System.out.println(list.get(i) + "         " + ctime);
		}
	}

}